﻿using System;

namespace Cxuu.Common
{
    public class FormatUtility
    {
        /// <summary>  
        /// 转换方法  
        /// </summary>  
        /// <param name="size">字节值</param>  
        /// <returns></returns>  
        public static string HumanReadableFilesize(long size)
        {
            String[] units = new String[] { "B", "KB", "MB", "GB", "TB", "PB" };
            double mod = 1024.0;
            int i = 0;
            while (size >= mod)
            {
                size = Convert.ToInt64(size / mod);
                i++;
            }
            //  return size + " " + units[i];
            return $"{size}{units[i]}";
        }
    }
}
